package com.lis.scf.common.dto;
import lombok.Data;

import java.io.Serializable;

/**
 * 统一响应DTO
 */
@Data
public class ResponseDTO<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;
    private String message;
    private T data;

    private ResponseDTO() {}

    public static <T> ResponseDTO<T> success() {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setCode(200);
        response.setMessage("操作成功");
        return response;
    }

    public static <T> ResponseDTO<T> success(T data) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setCode(200);
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static <T> ResponseDTO<T> fail(String message) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setCode(500);
        response.setMessage(message);
        return response;
    }

    public static <T> ResponseDTO<T> fail(int code, String message) {
        ResponseDTO<T> response = new ResponseDTO<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}